//
//  SystemUtils.m
//  tok
//
//  Created by Dragon on 12-11-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SystemUtils.h" 
#import "Reachability.h"

@implementation SystemUtils


//获取屏幕宽度
+(CGFloat) getScreenWidth{
    CGRect imageRect =[[UIScreen mainScreen]bounds];
    //1024
    return  imageRect.size.height;
}

//获取屏幕高度
+(CGFloat) getScreenHeight{
    CGRect imageRect =[[UIScreen mainScreen]bounds];
//    768
    return  imageRect.size.width-TOOLBAR_HEIGHT;
}

+(NSString *) getCurTime{
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //用[NSDate date]可以获取系统当前时间
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    return currentDateStr;

}
//获取IOS设备可用空间
+ (float)getFreeDiskspace {
    float totalSpace = 0.0f;
    float totalFreeSpace = 0.0f;
    NSError *error = nil;  
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  
    
    if (dictionary) {  
        NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];  
        NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
        totalSpace = [fileSystemSizeInBytes floatValue];
        totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
//        NSLog(@"Memory Capacity of %f MiB with %f MiB Free memory available.", ((totalSpace/1024.0f)/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f));
        totalFreeSpace=totalFreeSpace/(1024*1024);
    } else {  
//        NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);  
    }
    
    return totalFreeSpace;
}

+(BOOL)checkNetWork:(NSString *) url {
    BOOL isExistenceNetWork;
    Reachability *reachability = [Reachability reachabilityWithHostName:url];
    switch ([reachability currentReachabilityStatus]) {
        case NotReachable://无网络
            isExistenceNetWork = FALSE;
            break;
        case ReachableViaWWAN://使用3G或RPRS
            isExistenceNetWork = TRUE;
            break;
        case ReachableViaWiFi://使用WiFi
            isExistenceNetWork = TRUE;
            break;
    }
    return isExistenceNetWork;
}
@end
